#!/bin/bash
force=0
if [ $# -ne 0 ];then
    if [ x$1 == x"force" ];then
        force=1
   	echo "Force mount !!!"
   fi
fi

function mount_disk()
{
    space=$1
    mount_point=$2
    mount | grep -w "$mount_point"
    if [ $? -eq 0 ];then
        if [ $force -eq 1 ];then
    	    echo "linux123" | sudo -S umount $mount_point
        else
            return
        fi
    fi
    disk_name=`lsblk | grep $space | grep "disk" | awk '{print $1}'`
    if [ "x$disk_name" != "x" ];then
        part_name=`lsblk -l /dev/$disk_name | grep "part" | awk '{print $1}'`
        if [ "x$part_name" == "x" ];then
            part_name=$disk_name
        fi
        part_devname="/dev/"$part_name
        mount_path=`lsblk -l $part_devname | grep "$part_name" | awk '{print $7}'`
        if [ "x$mount_path" != "x$mount_point" ];then
            echo "linux123" | sudo -S mount -t ext4 -o errors=remount-ro,noatime,nodiratime,rw $part_devname $mount_point
            echo "mount $mount_point OK!!!"
        else
            echo "mounted $mount_point."
        fi
    else
        echo "Disk Space $space Not Finded."
    fi
}

function mount_bind()
{
    srcdir=$1
    tardir=$2
    mount | grep -w "$tardir"
    if [ $? -eq 0 ];then
        if [ $force -eq 1 ];then
            echo "linux123" | sudo -S umount $tardir
        else
            return
        fi
    fi
    if [ -d $srcdir ];then
        echo "linux123" | sudo -S mount -o bind $srcdir $tardir
    fi
}

mount_disk 260G /home/android
mount_disk 117G /home/vmuser
mount_disk 100G /home/data

mount_bind /home/vmuser/dsqiu/work/linux /home/dsqiu/work/linux
mount_bind /home/vmuser/dsqiu /home/dsqiu/vmuser
mount_bind /home/data /home/dsqiu/work/data

# mount | grep /home/vmuser > /dev/null
# if [ $? != 0 ];then
#     echo "linux123" | sudo -S mount -t ext4 -o errors=remount-ro,noatime,nodiratime,rw /dev/sdc1 /home/vmuser
#     echo "linux123" | sudo -S mount -o bind /home/vmuser/dsqiu/work/linux /home/dsqiu/work/linux
#     echo "linux123" | sudo -S mount -o bind /home/vmuser/dsqiu /home/dsqiu/vmuser
# fi
# mount | grep /home/data > /dev/null
# if [ $? != 0 ];then
#     echo "linux123" | sudo -S mount -t ext4 -o errors=remount-ro,noatime,nodiratime,rw /dev/sde /home/data
#     echo "linux123" | sudo -S mount -o bind /home/data /home/dsqiu/work/data
# fi
# mount | grep /home/android > /dev/null
# if [ $? != 0 ];then
#     echo "linux123" | sudo -S mount -t ext4 -o errors=remount-ro,noatime,nodiratime,rw /dev/sdd1 /home/android
# fi
